package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbContentMapper;
import com.dongdongshop.pojo.content.TbContent;
import com.dongdongshop.pojo.content.TbContentExample;
import com.dongdongshop.service.content.ContentService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Service
@Component
public class ContentServiceImpl implements ContentService {

    @Resource
    private TbContentMapper contentMapper;

    /*
    * 查询所有分类信息
    * */
    @Override
    public List<TbContent> findContentAll() {
        return contentMapper.selectByExample(null);
    }

    /*
    * 增加广告
    * */
    @Override
    public void addContent(TbContent c) {
        contentMapper.insertSelective(c);
    }

    /*
    * 根据主键id查询广告信息
    * */
    @Override
    public TbContent findContentById(Long id) {
        return contentMapper.selectByPrimaryKey(id);
    }

    /*
    * 修改广告信息
    * */
    @Override
    public void updateContentById(TbContent c) {
        contentMapper.updateByPrimaryKeySelective(c);
    }

    /*
    * 按照广告分类类型查询广告信息
    * */
    @Override
    public List<TbContent> findContentByCategoryId(Long categoryId) {
        TbContentExample example = new TbContentExample();
        TbContentExample.Criteria criteria = example.createCriteria();
        //根据类型id
        criteria.andCategoryIdEqualTo(categoryId);
        //有效的广告
        criteria.andStatusEqualTo("1");
        //顺序排序
        example.setOrderByClause("sort_order asc");
        return contentMapper.selectByExample(example);
    }
}
